<?php

namespace App\Models\Company;
use Illuminate\Database\Eloquent\Model;

class CompanyBasic extends Model{
    //设置表的类型和表名
    protected $table = 'company_basic';
    protected $primaryKey = 'id';
    public $timestamps = false;
    protected $guarded = [];
    public function company_job(){
        return $this->hasMany('App\Models\Company\CompanyJob','com_id','id');
    }

    /**
     * 获取用户信息
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function companyUser(){
        return $this->belongsTo('App\Models\Company\CompanyUser','uid','uid');
    }
    /**
     * 固定电话拆分成数组
     * @return array
     */
    public function getPhoneSplitAttribute()
    {
        $phoneArray = explode('-', trim($this->phone));//使用trim函数为了兼容老的数据(可以过几个版本删除此trim的函数)
        $count = count($phoneArray);
        $Array = [];
        switch ($count) {
            case 0;
                $Array[0] = '';
                $Array[1] = '';
                $Array[2] = '';
                break;
            case 1;//理论上不会出现此类情况
                $Array[0] = '';
                $Array[1] = $phoneArray[0];
                $Array[2] = '';
                break;
            case 2;
                $Array[0] = $phoneArray[0];
                $Array[1] = $phoneArray[1];
                $Array[2] = '';
                break;
            case 3;
                $Array[0] = $phoneArray[0];
                $Array[1] = $phoneArray[1];
                $Array[2] = $phoneArray[2];
                break;
        }
        return $Array;
    }
}